/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IngresoBebida.java
 *
 * Created on 14-abr-2012, 21:18:08
 */
package gui;

import java.util.ListIterator;
import javax.swing.JOptionPane;
import modelo.Alimento;
import modelo.Bebida;
import modelo.Cliente;
import modelo.Restaurante;

/**
 *
 * @author Lenovo
 */
public class IngresoBebida extends javax.swing.JFrame {

    /**
     * Creates new form IngresoBebida
     */
    private Restaurante restaurante;
    private int mesaPedido;
    private int sillaPedido;
    VentanaPrincipal v;

    public IngresoBebida(Restaurante restaurante, int mesaPedido, int sillaPedido) {
        initComponents();
        this.restaurante = restaurante;
        this.mesaPedido = mesaPedido;
        this.sillaPedido = sillaPedido;
        this.setLocationRelativeTo(null);
        cargarComboBebida();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPBebida = new javax.swing.JPanel();
        jLImgBebida = new javax.swing.JLabel();
        jCBBebida = new javax.swing.JComboBox();
        jLBebida = new javax.swing.JLabel();
        jLCantBebida = new javax.swing.JLabel();
        jSCantBebida = new javax.swing.JSpinner();
        jBAgregarBebida = new javax.swing.JButton();
        jBCancelarAgregBebida = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Restaurante \"Con Sabor\" - Adicionar Bebida");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPBebida.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Bebida", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 14), new java.awt.Color(204, 0, 102))); // NOI18N

        jLImgBebida.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/bebidas.jpg"))); // NOI18N
        jLImgBebida.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jCBBebida.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jCBBebida.setForeground(new java.awt.Color(153, 0, 51));
        jCBBebida.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione una opción" }));

        jLBebida.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLBebida.setForeground(new java.awt.Color(153, 0, 51));
        jLBebida.setText("Bebida a ordenar:");

        jLCantBebida.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLCantBebida.setForeground(new java.awt.Color(153, 0, 51));
        jLCantBebida.setText("Cantidad para este pedido:");

        javax.swing.GroupLayout jPBebidaLayout = new javax.swing.GroupLayout(jPBebida);
        jPBebida.setLayout(jPBebidaLayout);
        jPBebidaLayout.setHorizontalGroup(
            jPBebidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPBebidaLayout.createSequentialGroup()
                .addContainerGap(37, Short.MAX_VALUE)
                .addComponent(jLImgBebida)
                .addGap(32, 32, 32)
                .addGroup(jPBebidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPBebidaLayout.createSequentialGroup()
                        .addComponent(jLBebida)
                        .addGap(18, 18, 18)
                        .addComponent(jCBBebida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPBebidaLayout.createSequentialGroup()
                        .addComponent(jLCantBebida)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jSCantBebida, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(52, 52, 52))
        );
        jPBebidaLayout.setVerticalGroup(
            jPBebidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPBebidaLayout.createSequentialGroup()
                .addGroup(jPBebidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPBebidaLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPBebidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLBebida)
                            .addComponent(jCBBebida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(33, 33, 33)
                        .addGroup(jPBebidaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLCantBebida)
                            .addComponent(jSCantBebida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(42, 42, 42))
                    .addComponent(jLImgBebida))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jBAgregarBebida.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBAgregarBebida.setForeground(new java.awt.Color(204, 0, 102));
        jBAgregarBebida.setText("AGREGAR BEBIDA");
        jBAgregarBebida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBAgregarBebidaActionPerformed(evt);
            }
        });

        jBCancelarAgregBebida.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jBCancelarAgregBebida.setForeground(new java.awt.Color(204, 0, 102));
        jBCancelarAgregBebida.setText("CANCELAR");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(205, 205, 205)
                        .addComponent(jBAgregarBebida)
                        .addGap(56, 56, 56)
                        .addComponent(jBCancelarAgregBebida))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPBebida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPBebida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBAgregarBebida)
                    .addComponent(jBCancelarAgregBebida))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBAgregarBebidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBAgregarBebidaActionPerformed
        String alimento = (String) jCBBebida.getSelectedItem();
        int cantidadBebida = (Integer) jSCantBebida.getValue();
        Alimento ali = restaurante.buscarAlimento(alimento);
        if (ali != null) {
            ali.setCantidad(cantidadBebida);
            Cliente c = restaurante.getClientes()[mesaPedido][sillaPedido];
            String msj = c.modificarPedido(ali, cantidadBebida);
            JOptionPane.showMessageDialog(null, msj);

        } else {
            JOptionPane.showMessageDialog(null, "Este alimento no esta disponible en el menu");
        }
    }//GEN-LAST:event_jBAgregarBebidaActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        v.cargarConsumoActual();
    }//GEN-LAST:event_formWindowClosed

    /**
     * carga la bebida de tipo Bebida en el combo
     */
    public void cargarComboBebida() {
        jCBBebida.removeAllItems();
        ListIterator<Alimento> iterator = restaurante.getMenu().listIterator();
        while (iterator.hasNext()) {
            Alimento a = iterator.next();
            if (a instanceof Bebida) {
                Bebida c = (Bebida) a;
                jCBBebida.addItem(c.getNombre());
            }
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBAgregarBebida;
    private javax.swing.JButton jBCancelarAgregBebida;
    private javax.swing.JComboBox jCBBebida;
    private javax.swing.JLabel jLBebida;
    private javax.swing.JLabel jLCantBebida;
    private javax.swing.JLabel jLImgBebida;
    private javax.swing.JPanel jPBebida;
    private javax.swing.JSpinner jSCantBebida;
    // End of variables declaration//GEN-END:variables

}
